﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Linq.Expressions;
using MvcBoost;

namespace System.Web.Mvc.Html
{
    

    public static class HtmlCheckListExtensions
    {

        public static MvcHtmlString CheckListItemFor<TModel, TProperty>(this HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression, object value, bool isSelected, object htmlAttributes)
        {
        
            var itemMetadata = ModelMetadata.FromLambdaExpression(expression,html.ViewData);

            var propertyName = string.Format( "{0}", ExpressionHelper.GetExpressionText(expression) );            

            return html.Tag("input",null,
                MvcTools.Extend(new { @name = propertyName, @type = "checkbox", @value = value }, isSelected ? new { @checked = "checked" } : null, htmlAttributes)
                ,null);                    
        }
        
    }
    
}
